<--- %%NOBANNER%% --> nextlines.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| In word document, to move the cursor to the next line and overwrite|
| the contents in the next line;                                     |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| auguments:                                                         |
|   numoflines - how many lines you want to insert;                  |
|   insidedata - if you want to use it inside a a data step;         |
|   wordref - is not necessary, default is "wordsys";                |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example : %nextlines(T,2); / %nextlines(T); /%nextlines(2); /      |
|           %nextlines(2, T); / %nextlines ;                         |
| Usage:    %nextlines(numofcells, insidedata, wordref);             |
\-------------------<-- End of Files Created-->---------------------*/
%macro nextlines/parmbuff;
/*--------------------------------------------\
| Author:   Duo Zhou;                         |
| Created:  2-27-2001 10:48pm;                |
| Modified: 6-6-2001 8:24pm;                  |
| Purpose:  Move the cursor to the next line; |
\--------------------------------------------*/
%local _i_ _j_ npars numoflines insidedata par parcount arg fref numsid wsid rc;
%let parcount=1;
%let par&parcount=%qscan(&syspbuff, &parcount, %str( (),));
  %do %while(%length(&&par&parcount) gt 0);
     %let parcount=%eval(&parcount+1);
     %let par&parcount=%qscan(&syspbuff, &parcount, %str( (),));
  %end;
%let parcount =%eval(&parcount-1);
%if (%index(%upcase(&par1), T)) %then %do;
   %let insidedata=%qscan(&syspbuff,1,%str( (),));
   %if &parcount > 1 %then %do;
      %let numoflines=%qscan(&syspbuff,2,%str( (),));
   %end;
   %else %do;
      %let numoflines=;
   %end;
%end;
%else %do;
   %let numoflines=%qscan(&syspbuff,1,%str( (),));
   %if &parcount > 1 %then %do;
      %let insidedata=%qscan(&syspbuff,2,%str( (),));
      %let insidedata=%sysfunc(dequote(&insidedata));
   %end;
   %else %do;
      %let insidedata=F;
   %end;
%end;
%if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&numoflines))) or (&numoflines eq)  %then %do;
   %let numoflines=1;
%end;
%let arg=%qscan(&syspbuff,-1,%str((),));
%let arg=%sysfunc(dequote(&arg));
%let fref=; %let wsid=0;
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WORDREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINDOW=))) or
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WIN=)))
      %then %do;
   %let fref=%qscan(&arg, 2, %str(= ));
   %put --> Note: Checking the status of window "&fref" to see if it is open.;
%end;
%else %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&arg))) and (%quote(%upcase(&arg)) ne %quote(T)) and (%quote(%upcase(&arg))ne %quote(TRUE)) %then %do;
   %if not (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(=))) %then %do; 
      %let fref=%sysfunc(compress(&arg));
      %put --> Note: Checking the status of window "&fref" to see if it is open.;
   %end;
   %else %do;
      %put --> Alert! Keyword Parameter isn%str(%')t declared!;
   %end;
%end;
%else %do;
   %let fref=wordsys;
   %put --> Note: No window reference is specified%str(;) Checking the status of the default; 
   %put -->       window "&fref" to see if it is open.;
%end;
/****/
%if (&fref ne ) %then %do;
   %let wsid=%sysfunc(fopen(&fref,o,132,e));
%end;
%if &wsid %then %do;
   %let rc=%sysfunc(fclose(&wsid));
   %if (%quote(%upcase(&insidedata)) ne %quote(T)) and (%quote(%upcase(&insidedata))ne %quote(TRUE)) %then %do;
      data _null_;
         file &fref lrecl=2000;
         %do _i_=1 %to &numoflines;
         put '[LineDown 1]';
         put '[StartOfLine]';
         %end;
      run;
   %end;
   %else %do;
      file &fref lrecl=2000;
      %do _i_=1 %to &numoflines;
      put '[LineDown 1]';
      put '[StartOfLine]';
      %end;
   %end;
%end;
%else %do;
   %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.;
%end;
%mend nextlines;